package com.jeehentor.generate.utils;

/**
 * 下划线转驼峰
 */
public class CamelCaseUtil {

    /**
     * capitalizeFirstLetter为true 首字母大写
     * @param input
     * @param capitalizeFirstLetter
     * @return
     */
    public static String underscoreToCamelCase(String input, boolean capitalizeFirstLetter) {
        if (input == null || input.isEmpty()) {
            return input;
        }

        StringBuilder camelCaseString = new StringBuilder();
        boolean nextCharToUpper = capitalizeFirstLetter;

        for (int i = 0; i < input.length(); ++i) {
            char currentChar = input.charAt(i);

            if (currentChar == '_') {
                nextCharToUpper = true;
            } else {
                if (nextCharToUpper) {
                    camelCaseString.append(Character.toUpperCase(currentChar));
                    nextCharToUpper = false;
                } else {
                    camelCaseString.append(Character.toLowerCase(currentChar));
                }
            }
        }

        return camelCaseString.toString();
    }
}
